﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Netfraction.Hub.Scripting
{
    public class TypeBuilder
    {
        protected static Type GetClassType(string fullName)
        {
            if (fullName == null)
                throw new ArgumentNullException("fullName");

            Type classType = Type.GetType(fullName);
            if (classType == null)
                ThrowTypeLoadException(fullName);

            return classType;
        }

        protected static Type GetClassType(Assembly assembly, string fullName)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            if (fullName == null)
                throw new ArgumentNullException("fullName");

            Type classType = assembly.GetType(fullName);
            if (classType == null)
                ThrowTypeLoadException(fullName);

            return classType;
        }

        protected static void ThrowTypeLoadException(string typeFullName)
        {
            string msg = String.Format("Can't create an instance of permission class: {0}.", typeFullName);
            throw new TypeLoadException(msg);
            throw new ArgumentException(msg);
        }
    }
}
